import {homeMethod} from '@/utils/models/index.js'
const crudMethod = new homeMethod();
import GoTop from '@/components/go-top' // 咨询·意见
import serve from './module/serve' // 软件服务
import solution from './module/solution' // 解决方案
import dictionary from './module/dictionary'
import Manager from './module/manager'
import Footer from '@/components/footer-main'
export default {
  name: 'Home',
  components: { GoTop, serve, solution, dictionary, Manager, Footer},
  data() {
    return {
      productLoad: false,
      productData: [],
      serveLoad: false,
      serveData: [],
      solutionLoad: false,
      solutionData: [],
      articleLoad: false,
      articleData: [],
      partnerLoad: false,
      partnerData: [],
      dictionaryLoad: false,
      dictionaryData: [],
      articleBg: {
        backgroundImage: require('@/assets/images/companyNewsBg.png'),
        backgroundRepeat: 'no-repeat',
        backgroundPosition: 'center',
        backgroundSize: '100% 100%'
      },
    }
  },
  created() {
    document.title = 'APP-微信公众号-数据处理服务-应用软件|小程序定制开发-重庆朔悦科技'
    this.getProducts()
    this.getServes()
    this.getSolutions()
    this.getArticles()
    this.getPartners()
    this.getDictionarys()
  },
  methods: {
    // banner
    getProducts () {
      let _this = this
      _this.productLoad = true
      crudMethod.getProduct().then((res) => {
        _this.productLoad = false
        let {msg, code, data} = res;
        data.data.forEach(item => {
          item.productBannerImg = item.productBannerImg ? _this.baseURL + item.productBannerImg : ''
          item.productBannerRightImg = item.productBannerRightImg ? _this.baseURL + item.productBannerRightImg : ''
        })
        _this.productData = data.data
      })
    },
    // 软件服务
    getServes () {
      let _this = this
      _this.serveLoad = true
      crudMethod.getServe().then((res) => {
        _this.serveLoad = false
        let {msg, code, data} = res;
        data.data.forEach(item => {
          item.serveMinImg = item.serveMinImg ? item.serveMinImg.split(',') : []
          item.serveMinImg = item.serveMinImg.map((child) => {
            return _this.baseURL + child
          })
        })
        _this.serveData = data.data
      })
    },
    // 解决方案
    getSolutions () {
      let _this = this
      _this.solutionLoad = true
      crudMethod.getSolution().then((res) => {
        _this.solutionLoad = false
        let {msg, code, data} = res;
        data.data.forEach(item => {
          item.solutionMinImg = item.solutionMinImg ? _this.baseURL + item.solutionMinImg : ''
          item.solutionSilhouetteImg = item.solutionSilhouetteImg ? _this.baseURL + item.solutionSilhouetteImg : ''
        })
        _this.solutionData = data.data
      })
    },
    // 分页查询公司新闻
    getArticles () {
      let _this = this
      _this.articleLoad = true
      let params = {
        pageNum: 1,
        pageSize: 10,
        type: 1 // type 查询类型(1=前台首页查询出推荐新闻，其他则为默认查询全部以是否置顶排序)
      }
      crudMethod.getArticleFindPage(params).then((res) => {
        _this.articleLoad = false
        let {msg, code, data} = res;
        _this.articleData = data.rows
      })
    },
    // 合作伙伴
    getPartners() {
      let _this = this
      _this.partnerLoad = true
      crudMethod.getPartner().then((res) => {
        _this.partnerLoad = false
        let {msg, code, data} = res;
        data.data.forEach(item => {
           item.bannerImg = item.bannerImg ? _this.baseURL + item.bannerImg : ''
        })
        _this.partnerData = data.data
      })
    },
    // 漩涡
    getDictionarys() {
      let _this = this
      _this.dictionaryLoad = true
      crudMethod.getDictionary('统计').then((res) => {
        _this.dictionaryLoad = false
        let {msg, code, data} = res;
        _this.dictionaryData = data.data
      })
    }
  }
}
